package com.wujunshen.dumpling.core.execute;

import com.wujunshen.dumpling.core.Configuration;
import com.wujunshen.dumpling.core.engine.AbstractTemplateEngine;
import com.wujunshen.dumpling.core.engine.EngineFactory;
import com.wujunshen.dumpling.core.process.DataProcess;
import com.wujunshen.dumpling.database.metadata.model.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * 文档生成
 *
 * @author frankwoo
 */
@Slf4j
public class DocumentationExecute extends AbstractExecute {
  public DocumentationExecute(Configuration config) {
    super(config);
  }

  /** 执行 */
  @SneakyThrows
  @Override
  public void execute() {
    long start = System.currentTimeMillis();
    // 处理数据
    Data data = new DataProcess(config).process();
    // 产生文档
    AbstractTemplateEngine templateEngine =
        new EngineFactory(config.getEngineConfig()).newInstance();
    templateEngine.produce(data, getDocumentName(data.getSchema()));

    log.debug("结束生成数据字典, 耗时{}毫秒", System.currentTimeMillis() - start);
  }
}
